﻿Public Class frmCategoryeditor

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Cmd.Parameters("@name") = Me.txtname.Text
        Cmd.Parameters("@type") = Me.ComboBox1.SelectedValue
        If Me.txtid.Text = "" Then
            Cmd.ExecuteNonQuery("INSERT INTO Category VALUES(@name,@type,1);")
        Else
            Cmd.Parameters("@Id") = txtid.Text
            Cmd.ExecuteNonQuery("UPDATE Category SET CategoryName=@name,TypeId=@type WHERE CategoryId=@Id")
        End If

        Me.DialogResult = Windows.Forms.DialogResult.OK
        product.loaddata()
        Me.Close()
    End Sub

    Private Sub frmCategoryeditor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Loadtype()
    End Sub
    Public Sub Loadtype()
        Dim dr = Cmd.ExecuteDataReader("SELECT * FROM Type")
        Dim dt As New DataTable()
        dt.Load(dr)
        dr.Close()

        ComboBox1.DisplayMember = "TypeName"
        ComboBox1.ValueMember = "TypeId"
        ComboBox1.DataSource = dt
    End Sub
End Class